﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraGrid.Columns;
using DevExpress.XtraGrid.Views.Base;
using DevExpress.Utils.Menu;
using System.Collections;
using DevExpress.XtraGrid.Localization;


namespace NNLInterface
{
    public partial class frmBaseBasic : NNLInterface.frmBaseToolXC
    {

        private DevExpress.XtraEditors.Repository.RepositoryItemButtonEdit _repbuttonedit;
        public DevExpress.XtraEditors.Repository.RepositoryItemButtonEdit repbuttonedit
        {
            get
            {
                return this.repButtonEdit;
            }
            set
            {
                if (this.repButtonEdit == value)
                    return;
                this.repButtonEdit = value;
            }
        }

        private bool _SowCheckBox;
        public bool SowCheckBox
        {
            get { return _SowCheckBox; }
            set { _SowCheckBox = value; }
        }

        public frmBaseBasic()
        {
            InitializeComponent();
            this.ListGrid.MenuManager = this.barmanager;
            this.ListView.ShownEditor += new EventHandler(ListView_ShownEditor);
            common.ReStoreToolBarLayout(this.Name, this.barmanager);
            //设定皮肤风格
            int i = 0;
            foreach (DevExpress.Skins.SkinContainer skin in DevExpress.Skins.SkinManager.Default.Skins)
            {

                DevExpress.XtraBars.BarButtonItem itemStyle = new DevExpress.XtraBars.BarButtonItem();
                itemStyle.ItemClick += new DevExpress.XtraBars.ItemClickEventHandler(itemStyle_ItemClick);
                itemStyle.Caption = skin.SkinName;
                itemStyle.Tag = i;
                this.BarStyle.AddItem(itemStyle);
                i++;
            }
        }

        //皮肤切换
        void itemStyle_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            DevExpress.LookAndFeel.UserLookAndFeel.Default.SetSkinStyle(DevExpress.Skins.SkinManager.Default.Skins[(int)e.Item.Tag].SkinName);
            common.sysParameter.formskin = (common.FormSkin)((int)e.Item.Tag);

        }

        void ListView_ShownEditor(object sender, EventArgs e)
        {
            GridView view = sender as GridView;
            view.ActiveEditor.BackColor = common.sysParameter.CurRowBcolor;

        }

        private void ListView_ShowGridMenu(object sender, GridMenuEventArgs e)
        {
           

        }

        private void ListView_CustomDrawRowIndicator(object sender, RowIndicatorCustomDrawEventArgs e)
        {
            e.Appearance.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Far;
            if (e.Info.IsRowIndicator)
            {
                if (e.RowHandle >= 0)
                {
                    e.Info.DisplayText = (e.RowHandle + 1).ToString();
                }
                else if (e.RowHandle < 0 && e.RowHandle > -1000)
                {
                    e.Info.Appearance.BackColor = System.Drawing.Color.AntiqueWhite;
                    e.Info.DisplayText = "G" + e.RowHandle.ToString();
                }
            }

            if (e.RowHandle == DevExpress.XtraGrid.GridControl.InvalidRowHandle && SowCheckBox)
            {
                e.Handled = true;
                e.Painter.DrawObject(e.Info);

                Rectangle r = e.Bounds;
                //e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(100, 255, 0, 0)), r);
                //r.Height--; r.Width--;
                //e.Graphics.DrawRectangle(Pens.Red, r);

                StringFormat format = new StringFormat();
                format.LineAlignment = StringAlignment.Center;
                format.Alignment = StringAlignment.Center;
                if (this.ListView.RowCount >= 1)
                    if (Convert.ToInt32(this.ListGrid.Tag) == 0)
                    {
                        e.Graphics.DrawImage(imgList.Images[0], (r.Width - imgList.Images[0].Width) / 2+3, (r.Height - imgList.Images[0].Height) / 2+3);
                    }
                    else
                    {
                        e.Graphics.DrawImage(imgList.Images[1], (r.Width - imgList.Images[0].Width) / 2+3, (r.Height - imgList.Images[0].Height) / 2+3);
                    }
                else
                {
                    e.Graphics.DrawString("", this.Font, new SolidBrush(Color.White), r, format);
                }

            }

        }

        private void frmBaseBasic_FormClosing(object sender, FormClosingEventArgs e)
        {
            
        }
    }
}
